package com.of.controller;

import com.of.pojo.ItemCat;
import com.of.service.ItemCatService;
import com.of.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {

    @Autowired
    private ItemCatService itemCatService;

    /**
     * 需求: 查询三级商品分类信息
     * URL地址: /itemCat/findItemCatList/{level}
     * 参数:    level  1/2/3
     * 返回值:  SysResult(三级菜单)
     */
    @GetMapping("/findItemCatList/{level}")
    public SysResult findItemCatList(@PathVariable Integer level){
        List<ItemCat> catList = itemCatService.findItemCatList(level);
        return SysResult.success(catList);
    }
    /*
    * 需求:
    * 实现商品分类新增操作
    * url：/itemCat/saveItemCat
    *参数：json串
    * 提交的方式：post
    * 返回值 SysResult
    * */
    @PostMapping("/saveItemCat")
    @Transactional
    public SysResult saveItemCat(@RequestBody ItemCat itemCat){
        itemCatService.saveItemCat(itemCat);
        return SysResult.success();
    }
    /**
     * 删除商品分类数据
     * url：/itemCat/deleteItemCat
     * 参数 id、level
     * 返回值 SysResult
     */
    @DeleteMapping("/deleteItemCat")
    @Transactional
    public SysResult deleteItemCat(ItemCat itemCat){
        itemCatService.deleteItemCat(itemCat);
        return SysResult.success();
    }
    @PutMapping("/status/{id}/{status}")
    @Transactional
    public SysResult updateStatus(ItemCat itemCat){
        itemCatService.updateStatus(itemCat);
        return SysResult.success();
    }
    @PutMapping("/updateItemCat")
    @Transactional
    public SysResult updateItemCat(@RequestBody ItemCat itemCat){
        itemCatService.updateItemCat(itemCat);
        return SysResult.success();
    }


}
